package main

import (
	"chapter1/src/client"
	"fmt"
	"net/rpc"
)

/**
 * Created with Goland.
 * User: 令狐飞侠
 * Date: 2022-1-29
 * Description: 驱动函数
 */
func main() {
	tcpStr := "tcp"
	serverUrl := "127.0.0.1:8086"
	serviceMethod:="LhServer.Rec"



	// 1 建立服务器端的连接
	clientCon, err := rpc.Dial(tcpStr, serverUrl)
	if err != nil {
		fmt.Println("dial failed..", err.Error())
	}else{
		fmt.Println("dial successed..", serverUrl)
	}

	// 2 调用服务器端的接口struct（函数）
	var res client.Response
	err = clientCon.Call(serviceMethod, &struct{}{}, &res)
	if err != nil {
		fmt.Println("failed to Call..", err.Error())
	}else{
		resStr := string(res.Data)
		fmt.Println("rpc调用结果:", resStr)
	}
	clientCon.Close()
}
